package net.tribal.escpos.services

import javax.print.*
import javax.print.attribute.*
import javax.print.attribute.standard.*
import javax.print.event.*

class EscPosService{
	
	def printFile(file, printerName){
		def stream = new ByteArrayInputStream(file.getBytes("utf-8")) 
		def flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
		
		def mydoc = new SimpleDoc(stream, flavor, null);

		def printServices = PrintServiceLookup.lookupPrintServices(flavor, null);
		def ps = printServices.find{it.name == printerName}
		if(ps){
			DocPrintJob job = ps.createPrintJob();
			job.print(mydoc, null);
		}else{
			println "Printer does not exist"
		}
	}
}
